import {
  createRouter,
  createWebHistory
} from 'vue-router'

const routes = [{
  // path 路由地址和 component组件之间有对应的映射关系
  path: '/login',
  name: 'login',
  // component是一个组件 导入
  component: () => import('../views/Login.vue'),
  meta: {
    title: '登录'
  },
},
{
  path: '/',
  redirect: '/dashboard'
},
{
  path: '/',
  component: () => import('../views/Home.vue'),
  meta: {
    title: ''
  },
  children: [{
    path: '/dashboard',
    name: 'dashboard',
    component: () =>
      import(
        /* webpackChunkName: "dashboard" */
        '../views/Dashboard.vue'
      ),
    meta: {
      title: '系统首页',
      permission: true
    }
  },
  {
    path: '/personalInfo',
    name: 'personalInfo',
    component: () =>
      import(
        /* webpackChunkName: "personalInfo" */
        '../views/user/personalInfo.vue'
      ),
    meta: {
      title: '个人信息',
      permission: true
    }
  },
  {
    path: '/changePassword',
    name: 'changePassword',
    component: () =>
      import(
        /* webpackChunkName: "changePassword" */
        '../views/user/changePassword.vue'
      ),
    meta: {
      title: '修改密码',
      permission: true
    }
  },
  {
    path: '/dict',
    name: 'dict',
    component: () =>
      import(
        /* webpackChunkName: "dict" */
        '../views/configInfo/Dict.vue'
      ),
    meta: {
      title: '字典管理',
      permission: true
    }
  },
  {
    path: '/resourceInfo',
    name: 'resourceInfo',
    component: () =>
      import(
        /* webpackChunkName: "resourceInfo" */
        '../views/configInfo/ResourceInfo.vue'
      ),
    meta: {
      title: '资源信息',
      permission: true
    }
  },
  {
    path: '/menuInfo',
    name: 'menuInfo',
    component: () =>
      import(
        /* webpackChunkName: "menuInfo" */
        '../views/configInfo/MenuInfo.vue'
      ),
    meta: {
      title: '菜单信息',
      permission: true
    }
  },
  {
    path: '/softwareUpgrade',
    name: 'softwareUpgrade',
    component: () =>
      import(
        /* webpackChunkName: "softwareUpgrade" */
        '../views/configInfo/softwareUpgrade.vue'
      ),
    meta: {
      title: '升级信息',
      permission: true
    }
  },
  {
    path: '/roleInfo',
    name: 'roleInfo',
    component: () =>
      import(
        /* webpackChunkName: "roleInfo" */
        '../views/configInfo/roleInfo.vue'
      ),
    meta: {
      title: '角色信息',
      permission: true
    }
  },
  {
    path: '/customerServicClass',
    name: 'customerServicClass',
    component: () =>
      import(
        /* webpackChunkName: "customerServicClass" */
        '../views/configInfo/customerServicClass.vue'
      ),
    meta: {
      title: '客服分类信息',
      permission: true
    }
  },
  {
    path: '/customerServicList',
    name: 'customerServicList',
    component: () =>
      import(
        /* webpackChunkName: "customerServicList" */
        '../views/configInfo/customerServicList.vue'
      ),
    meta: {
      title: '客服列表信息',
      permission: true
    }
  },
  {
    path: '/userInfo',
    name: 'userInfo',
    component: () =>
      import(
        /* webpackChunkName: "userInfo" */
        '../views/user/userInfo.vue'
      ),
    meta: {
      title: '用户信息',
      permission: true
    }
  },
  {
    path: '/expressInfo',
    name: 'expressInfo',
    component: () =>
      import(
        /* webpackChunkName: "expressInfo" */
        '../views/configInfo/expressInfo.vue'
      ),
    meta: {
      title: '物流公司',
      permission: true
    }
  },
  {
    path: '/appUserInfo',
    name: 'appUserInfo',
    component: () =>
      import(
        /* webpackChunkName: "appUserInfo" */
        '../views/user/AppUserInfo.vue'
      ),
    meta: {
      title: '用户列表',
      permission: true
    }
  },

  {
    path: '/redEnvelopeManagement',
    name: 'redEnvelopeManagement',
    component: () =>
      import(
        /* webpackChunkName: "redEnvelopeManagement" */
        '../views/moneyManager/redEnvelopeManagement.vue'
      ),
    meta: {
      title: '红包管理',
      permission: true
    }
  },
  {
    path: '/redEnvelopeInfo',
    name: 'redEnvelopeInfo',
    component: () =>
      import(
        /* webpackChunkName: "redEnvelopeInfo" */
        '../views/moneyManager/redEnvelopeInfo.vue'
      ),
    meta: {
      title: '红包明细',
      permission: true
    }
  },
  {
    path: '/goldManagement',
    name: 'goldManagement',
    component: () =>
      import(
        /* webpackChunkName: "goldManagement" */
        '../views/moneyManager/goldManagement.vue'
      ),
    meta: {
      title: '金币管理',
      permission: true
    }
  },
  {
    path: '/goldInfo',
    name: 'goldInfo',
    component: () =>
      import(
        /* webpackChunkName: "goldInfo" */
        '../views/moneyManager/goldInfo.vue'
      ),
    meta: {
      title: '金币明细',
      permission: true
    }
  },
  {
    path: '/categoriesInfo',
    name: 'categoriesInfo',
    component: () =>
      import(
        /* webpackChunkName: "categoriesInfo" */
        '../views/redPacketMallManage/categoriesInfo.vue'
      ),
    meta: {
      title: '分类管理',
      permission: true
    }
  },
  {
    path: '/mallGoodsInfo',
    name: 'mallGoodsInfo',
    component: () =>
      import(
        /* webpackChunkName: "mallGoodsInfo" */
        '../views/redPacketMallManage/mallGoodsInfo.vue'
      ),
    meta: {
      title: '商品管理',
      permission: true
    }
  },
  {
    path: '/freighTemplate',
    name: 'freighTemplate',
    component: () =>
      import(
        /* webpackChunkName: "freighTemplate" */
        '../views/redPacketMallManage/freighTemplate.vue'
      ),
    meta: {
      title: '运费模板',
      permission: true
    }
  },
  {
    path: '/advertisingType',
    name: 'advertisingType',
    component: () =>
      import(
        /* webpackChunkName: "AdvertisingType" */
        '../views/advertisingManager/advertisingType.vue'
      ),
    meta: {
      title: '广告类型',
      permission: true
    }
  },
  {
    path: '/advertisingInfo',
    name: 'advertisingInfo',
    component: () =>
      import(
        /* webpackChunkName: "AdvertisingType" */
        '../views/advertisingManager/advertisingInfo.vue'
      ),
    meta: {
      title: '广告列表',
      permission: true
    }
  },
  {
    path: '/redPacketMallOrderInfo',
    name: 'redPacketMallOrderInfo',
    component: () =>
      import(
        /* webpackChunkName: "redPacketMallOrderInfo" */
        '../views/orderManage/redPacketMallOrderInfo.vue'
      ),
    meta: {
      title: '红包商城订单',
      permission: true
    }
  },
  {
    path: '/organizationInfo',
    name: 'organizationInfo',
    component: () =>
      import(
        /* webpackChunkName: "organizationInfo" */
        '../views/configInfo/organizationInfo.vue'
      ),
    meta: {
      title: '组织信息',
      permission: true
    }
  }
  ]
},
{
  path: '/404',
  component: () => import('../views/404.vue'),
  meta: {
    title: '404'
  },
},
{
  path: '/403',
  component: () => import('../views/403.vue'),
  meta: {
    title: '403'
  },
},
{
  path: "/:pathMatch(.*)*",
  redirect: '/404'
}
]

const router = createRouter({
  history: createWebHistory(),
  routes
})


export default router;

/* 获取所有的路由 */
export let getAllRouter = [];
handleGetAllRouter(routes);
function handleGetAllRouter (routes) {
  for (let i = 0; i < routes.length; i++) {
    if (routes[i].children) {
      handleGetAllRouter(routes[i].children)
    } else {
      getAllRouter.push(routes[i].path);
    }
  }
}